home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / pd / utilities / tinymeter / source / tinymeter_main / display.c next >
C/C++ Source or Header  |  1996-05-20  |  6KB  |  214 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <intuition/intuition.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/intuitionbase.h>
  8. #include <intuition/classusr.h>
  9. #include <intuition/gadgetclass.h>
  10. #include <intuition/cghooks.h>
  11. #include <intuition/icclass.h>
  12. #include <intuition/classes.h>
  13. #include <intuition/sghooks.h>
  14. #include <intuition/screens.h>
  15. #include <datatypes/datatypesclass.h>
  16. #include <datatypes/datatypes.h>
  17. #include <datatypes/pictureclass.h>
  18. #include <libraries/SysInfo.h>
  19. #include <libraries/gadtools.h>
  20. #include <graphics/gfxbase.h>
  21. #include <graphics/text.h>
  22. #include <graphics/gfxmacros.h>
  23. #include <utility/tagitem.h>
  24. #include <utility/hooks.h>
  25. #include <string.h>
  26. #include <clib/macros.h>
  27. #include "gaugeclass.h"
  28. #include "launchclass.h"
  29. #include "tinymeter.h"
  30.  
  31. extern struct Library *RetinaBase;
  32.  
  33. /* the only two globals */
  34.  
  35. extern ULONG    maximum,
  36.         idle;
  37.  
  38. drawBackground(struct tm_sys_set *set,struct tm_data *data)
  39. {
  40.     struct RastPort *rp=data->win->RPort;
  41.     UWORD  x,y;
  42.  
  43.     x=data->win->Width-1;
  44.     y=data->win->Height-1;
  45.  
  46.     if(data->bg_bm)
  47.     {
  48.     BltBitMapRastPort(data->bg_bm,0,0,rp,0,0,x+1,y+1,0xc0);
  49.     FreeBitMap(data->bg_bm); data->bg_bm=0L;
  50.     }
  51.     else
  52.     {
  53.     SetAPen(rp,data->bg_color);
  54.     RectFill(rp,0,0,x,y);
  55.     }
  56.  
  57.     SetAPen(rp,data->bright_color);
  58.     switch (set->bd_type)
  59.     {
  60.     case    bd_simple:
  61.         RectFill(rp,0,0,x,0);
  62.         RectFill(rp,0,0,0,y);
  63.         RectFill(rp,x,0,x,y);
  64.         RectFill(rp,0,y,x,y);
  65.         break;
  66.     case    bd_standard:
  67.         RectFill(rp,0,0,x,0);
  68.         RectFill(rp,0,0,0,y);
  69.         SetAPen(rp,data->dark_color);
  70.         RectFill(rp,x,1,x,y);
  71.         RectFill(rp,1,y,x,y);
  72.         break;
  73.     case    bd_double:
  74.         SetAPen(rp,data->dark_color);
  75.         RectFill(rp,0,0,x,0);
  76.         RectFill(rp,0,0,0,y);
  77.         RectFill(rp,1,y-1,x-1,y-1);
  78.         RectFill(rp,x-1,2,x-1,y-1);
  79.         SetAPen(rp,data->bright_color);
  80.         RectFill(rp,x,1,x,y);
  81.         RectFill(rp,1,y,x,y);
  82.         RectFill(rp,1,1,x-1,1);
  83.         RectFill(rp,1,1,1,y-1);
  84.         break;
  85.     }
  86. }
  87.  
  88. allocGadgets(struct tm_sys_set *set, struct tm_data *data, Class *gclass, Class *lclass)
  89. {
  90.     struct  tm_gau_set *many;
  91.     ULONG   i,y_pos,j,tmp,x;
  92.     int     foo;
  93.     
  94.     for(i=0,many=data->list;i<data->num_of_gaug;i++)
  95.     {
  96.     switch (many->type)
  97.     {
  98.         case    typ_image:
  99.             foo=0;
  100.             break;
  101.         case    typ_none:
  102.             data->gdg[i]=0L;
  103.             foo=0;
  104.             break;
  105.         case    typ_simplelauncher:
  106.         case    typ_iconlauncher:
  107.             foo=2;
  108.             break;
  109.         default:
  110.             foo=1;
  111.             break;
  112.     }
  113.     tmp=i/set->colums;
  114.     if(set->lay_falling)
  115.     {
  116.         y_pos=set->win_border_y+(tmp*set->win_space_y);
  117.         for(j=(i-(tmp*set->colums));j<i;j+=set->colums) y_pos+=data->gauge_y_size_falling[j];
  118.     }
  119.     else
  120.     {
  121.         y_pos= set->win_border_y+(tmp*set->win_space_y)+((data->gauge_y_size[tmp]-data->gauge_y_size_falling[i])>>1);
  122.         for(j=0;j<tmp;j++) y_pos+=data->gauge_y_size[j];
  123.     }
  124.     data->gauge_y_pos[i]=y_pos;
  125.     x=set->win_border_x+((i)%set->colums)*data->gauge_x_size+((i)%set->colums)*set->win_space_x;
  126.     switch (foo)
  127.     {
  128.         case    1 :  data->gdg[i]=(struct Gadget *)NewObject(gclass, NULL,
  129.                 GA_ID,              0xFFF4,
  130.                 GA_Top,             y_pos,
  131.                 GA_Left,            x,
  132.                 GA_Width,           data->gauge_x_size,
  133.                 GA_Height,          data->gauge_y_size_falling[i],
  134.                 GAU_Type,           many->gauge_type,
  135.                 GAU_Label,          many->label,
  136.                 GAU_TextFormat,     many->format,
  137.                 GAU_TextFont,       data->Font[i],
  138.                 GAU_LabelPos,       data->labelpos,
  139.                 GAU_FmtIndent,      many->indent,
  140.  
  141.                 GAU_3D,             many->sty_3d,
  142.                 GAU_Border,         many->sty_border,
  143.                 GAU_Background,     many->sty_bg,
  144.                 GAU_ShadowLabel,    many->sty_shadow,
  145.                 GAU_NoGauge,        many->sty_nogauge,
  146.                 GAU_NoFormat,       many->sty_noformat,
  147.                 GAU_NoBase,         many->sty_nobase,
  148.                 GAU_Expansion,      &many->expansion[0],
  149.                 GAU_DisWhat,        many->type,
  150.  
  151.                 GAU_ColLabel,       &many->Colors[col_label],
  152.                 GAU_ColFormat,      &many->Colors[col_format],
  153.                 GAU_ColBase,        &many->Colors[col_base],
  154.                 GAU_ColCurrent,     &many->Colors[col_current],
  155.                 GAU_ColNegative,    &many->Colors[col_negative],
  156.                 GAU_ColBrightEdg,   &many->Colors[col_bright],
  157.                 GAU_ColDarkEdg,     &many->Colors[col_dark],
  158.                 GAU_ColBackground,  &many->Colors[col_bg],
  159.  
  160.                 TAG_END);
  161.             if(!data->gdg[i]) show(err_noboo);
  162.             break;
  163.         case    2 :
  164.             data->gdg[i]=(struct Gadget *)NewObject(lclass, NULL,
  165.                 GA_ID,              i,
  166.                 GA_Top,             y_pos,
  167.                 GA_Left,            x,
  168.                 GA_Width,           data->gauge_x_size,
  169.                 GA_Height,          data->gauge_y_size_falling[i],
  170.                 GA_Immediate,       TRUE,
  171.                 GA_RelVerify,       TRUE,
  172.  
  173.                 LAU_File,           &many->expansion[0],
  174.                 LAU_TextFont,       data->Font[i],
  175.                 LAU_3D,             many->sty_3d,
  176.                 LAU_Border,         many->sty_border,
  177.                 LAU_Background,     many->sty_bg,
  178.                 LAU_ShadowLabel,    many->sty_shadow,
  179.                 LAU_Down,           many->sty_nogauge,
  180.                 LAU_Transparent,    many->sty_noformat,
  181.                 LAU_Screen,         data->scr,
  182.                 LAU_Indent,         many->indent,
  183.                 LAU_Type,           many->type,
  184.  
  185.                 LAU_ColLabel,       &many->Colors[col_label],
  186.                 LAU_ColEntry,       &many->Colors[col_format],
  187.                 LAU_ColHalfBright,  &many->Colors[col_base],
  188.                 LAU_ColHalfShadow,  &many->Colors[col_current],
  189.                 LAU_ColCursor,      &many->Colors[col_negative],
  190.                 LAU_ColBrightEdg,   &many->Colors[col_bright],
  191.                 LAU_ColDarkEdg,     &many->Colors[col_dark],
  192.                 LAU_ColBackground,  &many->Colors[col_bg],
  193.                 TAG_END);
  194.             if(!data->gdg[i]) show(err_noboo);
  195.             break;
  196.  
  197.  
  198.     }
  199.     many=many->next;
  200.     }
  201. }
  202.  
  203. removeGadgets(struct tm_sys_set *set, struct tm_data *data)
  204. {
  205.     int i;
  206.  
  207.     for(i=0;i<data->num_of_gaug;i++)
  208.     if(data->gdg[i])
  209.     {
  210.         DisposeObject(data->gdg[i]);
  211.         data->gdg[i]=0L;
  212.     }
  213. }
  214.